package jjn.round1;

/**
 * @author Jjn
 * @since 2022/8/14 23:13
 */
public class LeetCode283_MoveZeroes {

    public void moveZeroes(int[] nums) {
        int i = 0, j = 0, total = nums.length - 1;
        while (j <= total) {
            if (nums[j] != 0) {
                swap(nums, j, i);
                i++;
            }
            j++;
        }
    }

    private void swap(int[] nums, int i, int j) {
        if (i >= nums.length || j >= nums.length) {
            return;
        }
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
